package com.shuoyue.ycgk.ui.mok;

import com.shuoyue.ycgk.base.BaseModel;
import com.shuoyue.ycgk.base.BasePresenter;
import com.shuoyue.ycgk.base.BaseResult;
import com.shuoyue.ycgk.base.BaseView;
import com.shuoyue.ycgk.base.ListWithPage;
import com.shuoyue.ycgk.entity.Mok;
import com.shuoyue.ycgk.entity.MokType;
import com.shuoyue.ycgk.net.RetrofitClient;
import com.shuoyue.ycgk.net.base.ApiSubscriber;
import com.shuoyue.ycgk.net.gsondefaultadapter.Optional;

import java.util.List;

import io.reactivex.Observable;

public interface MokContract {
    interface View extends BaseView {
        void setMokList(List<Mok> mokList);

        void setMokTypeList(List<MokType> mokList);
    }

    class Presenter extends BasePresenter<View> {
        Model model = new Model();

        public void getMokList(int subjectTypeId) {
            apply(model.getMokList(subjectTypeId))
                    .subscribe(new ApiSubscriber<Optional<List<Mok>>>(mView, this) {
                        @Override
                        public void onNext(Optional<List<Mok>> listOptional) {
                            super.onNext(listOptional);
                            mView.setMokList(listOptional.getIncludeNull());
                        }
                    });
        }

        public void getMokType() {
            apply(model.getMokTypeList())
                    .subscribe(new ApiSubscriber<Optional<List<MokType>>>(mView, this) {
                        @Override
                        public void onNext(Optional<List<MokType>> listOptional) {
                            super.onNext(listOptional);
                            mView.setMokTypeList(listOptional.getIncludeNull());
                        }
                    });
        }

        public void getMokRul(int subjectTypeId) {
            apply(model.getMokList(subjectTypeId))
                    .subscribe(new ApiSubscriber<Optional<List<Mok>>>(mView, this) {
                        @Override
                        public void onNext(Optional<List<Mok>> listOptional) {
                            super.onNext(listOptional);
                            mView.setMokList(listOptional.getIncludeNull());
                        }
                    });
        }
    }

    class Model extends BaseModel {
        Observable<BaseResult<List<Mok>>> getMokList(int subjectId) {
            return RetrofitClient.getInstance().getApi().getMokList(subjectId);
        }

        Observable<BaseResult<List<MokType>>> getMokTypeList() {
            return RetrofitClient.getInstance().getApi().getMokTypeList();
        }

    }
}
